package com.sky.demo04cas;

import java.util.concurrent.atomic.AtomicInteger;

public class Demo01 {

    private static AtomicInteger number = new AtomicInteger();

    public static void main(String[] args) throws InterruptedException {

        Runnable runnable = () -> {
            for (int i = 0; i < 1000; i++) {
                // 变量赋值原子性
                number.incrementAndGet();
            }
        };


        for (int i = 0; i < 5; i++) {
            Thread thread = new Thread(runnable);
            thread.start();
        }

        Thread.sleep(2000);
        System.out.println("number = " + number.get());
    }
}
